import QtQuick 2.15
import QtQuick.Controls 2.15

Item {
    id: mcAchievement
    width: 500
    height: 100
    
    signal finished()
    
    property string title: "获得成就!"
    property string context: "成就描述"
    property string imgSrc: "../image/anim/mirror.png"
    property bool noclip: false
    
    // 初始位置在屏幕上方外部
    x: parent.width - width
    y: -height
    
    // 背景
    Image {
        id: background
        source: "../image/anim/pic.png"
        width: parent.width
        height: parent.height
        fillMode: Image.Stretch
        
        /* Rectangle {
            anchors.fill: parent
            color: "transparent"
            border.color: "#40000000"
            border.width: 2
        } */
    }
    
    // 成就图标
    Image {
        id: achievementIcon
        source: imgSrc
        width: parent.height * 0.7
        height: parent.height * 0.7
        sourceClipRect: noclip ? undefined : Qt.rect(61, 20, 128, 128)
        clip: true
        anchors {
            left: parent.left
            leftMargin: parent.height * 0.15
            verticalCenter: parent.verticalCenter
        }
        fillMode: Image.PreserveAspectFit
    }
    
    // 成就标题
    Text {
        id: titleText
        text: title
        color: "yellow"
        font {
            family: minecraftFont.name
            pixelSize: parent.width / 250 * 10
        }
        anchors {
            left: achievementIcon.right
            leftMargin: parent.width * 0.036
            top: parent.top
            topMargin: parent.height * 0.186
        }
        
        /* style: Text.Outline
        styleColor: "#80000000" */
    }
    
    // 成就描述
    Text {
        id: contextText
        text: context
        color: "white"
        font {
            family: minecraftFont.name
            pixelSize: parent.width / 250 * 10
        }
        anchors {
            left: achievementIcon.right
            leftMargin: parent.width * 0.036
            top: titleText.bottom
            topMargin: parent.height * 0.1
        }
        
        /* style: Text.Outline
        styleColor: "#80000000" */
    }
    
    // 显示动画
    SequentialAnimation {
        id: showAnimation
        running: false
        
        // 滑入动画
        NumberAnimation {
            target: mcAchievement
            property: "y"
            from: -height
            to: 20
            duration: 500
            easing.type: Easing.OutBack
        }
        
        // 停留时间
        PauseAnimation { duration: 3000 }
        
        // 淡出动画
        NumberAnimation {
            target: mcAchievement
            property: "opacity"
            from: 1.0
            to: 0.0
            duration: 500
        }
        
        onFinished: {
            mcAchievement.finished();
        }
    }
    
    // 显示成就
    function show() {
        opacity = 1.0;
        showAnimation.start();
    }
}